home *** CD-ROM | disk | FTP | other *** search
- Public Class Typography
- Inherits System.Windows.Forms.Form
-
- #Region " Windows Form Designer generated code "
-
- Public Sub New()
- MyBase.New()
-
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
-
- 'Add any initialization after the InitializeComponent() call
-
- End Sub
-
- 'Form overrides dispose to clean up the component list.
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
- Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
- Friend WithEvents mnuEnumerateFonts As System.Windows.Forms.MenuItem
- Friend WithEvents mnuFontStyles As System.Windows.Forms.MenuItem
- Friend WithEvents mnuTextureBrush As System.Windows.Forms.MenuItem
- Friend WithEvents mnuAlignedText As System.Windows.Forms.MenuItem
- Friend WithEvents mnuVerticalText As System.Windows.Forms.MenuItem
- Friend WithEvents mnuTabStops As System.Windows.Forms.MenuItem
- Friend WithEvents mnuAntialiasing As System.Windows.Forms.MenuItem
-
- 'Required by the Windows Form Designer
- Private components As System.ComponentModel.Container
-
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- Me.mnuFontStyles = New System.Windows.Forms.MenuItem()
- Me.mnuTabStops = New System.Windows.Forms.MenuItem()
- Me.mnuVerticalText = New System.Windows.Forms.MenuItem()
- Me.mnuEnumerateFonts = New System.Windows.Forms.MenuItem()
- Me.mnuTextureBrush = New System.Windows.Forms.MenuItem()
- Me.mnuAlignedText = New System.Windows.Forms.MenuItem()
- Me.MainMenu1 = New System.Windows.Forms.MainMenu()
- Me.MenuItem1 = New System.Windows.Forms.MenuItem()
- Me.mnuAntialiasing = New System.Windows.Forms.MenuItem()
- '
- 'mnuFontStyles
- '
- Me.mnuFontStyles.Index = 1
- Me.mnuFontStyles.Text = "Font styles"
- '
- 'mnuTabStops
- '
- Me.mnuTabStops.Index = 5
- Me.mnuTabStops.Text = "Tab Stops"
- '
- 'mnuVerticalText
- '
- Me.mnuVerticalText.Index = 4
- Me.mnuVerticalText.Text = "Vertical Text"
- '
- 'mnuEnumerateFonts
- '
- Me.mnuEnumerateFonts.Index = 0
- Me.mnuEnumerateFonts.Text = "Enumerate Font Families"
- '
- 'mnuTextureBrush
- '
- Me.mnuTextureBrush.Index = 2
- Me.mnuTextureBrush.Text = "Textured Brushes"
- '
- 'mnuAlignedText
- '
- Me.mnuAlignedText.Index = 3
- Me.mnuAlignedText.Text = "Aligned Text"
- '
- 'MainMenu1
- '
- Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
- '
- 'MenuItem1
- '
- Me.MenuItem1.Index = 0
- Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuEnumerateFonts, Me.mnuFontStyles, Me.mnuTextureBrush, Me.mnuAlignedText, Me.mnuVerticalText, Me.mnuTabStops, Me.mnuAntialiasing})
- Me.MenuItem1.Text = "Examples"
- '
- 'mnuAntialiasing
- '
- Me.mnuAntialiasing.Index = 6
- Me.mnuAntialiasing.Text = "Anti-aliasing"
- '
- 'Typography
- '
- Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
- Me.ClientSize = New System.Drawing.Size(680, 353)
- Me.Menu = Me.MainMenu1
- Me.Name = "Typography"
- Me.Text = "Typography"
-
- End Sub
-
- #End Region
-
- Private Sub mnuEnumerateFonts_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuEnumerateFonts.Click
- ' Draw all font names on form
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
-
- ' Get the collection of installed Fonts.
- Dim fonts As New System.Drawing.Text.InstalledFontCollection()
- ' Get an array with all installed font families.
- Dim fontFamilies() As FontFamily = fonts.Families
-
- ' Uncomment next statement to see only fonts for video device.
- ' fontFamilies = FontFamily.GetFamilies(gr)
-
- ' Create a comma-delimited list of font families names.
- Dim list As String
- Dim font As FontFamily
- For Each font In fontFamilies
- If list <> "" Then list &= ", "
- list &= font.Name
- Next
-
-
- ' use a font for printing.
- Dim fnt As New Font("Arial", 10, FontStyle.Regular)
- ' Keep output inside the form client area.
- Dim rectF As New RectangleF(0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height)
- gr.DrawString(list, fnt, Brushes.Black, rectF)
-
- fnt.Dispose()
- gr.Dispose()
-
- End Sub
-
- Private Sub mnuFontStyles_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuFontStyles.Click
- ' let the menu disappear.
- Threading.Thread.Sleep(500)
-
- ' Draw all font names on form
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
-
- ' Create a font from a family and a size in points.
- Dim font1 As New Font("Arial", 12, GraphicsUnit.Pixel)
- ' Create a font from a family, a size, and a style.
- Dim font2 As New Font("Arial", 14, FontStyle.Bold)
- ' Create a font from a family, a size, and two combined styles.
- Dim font3 As New Font("Arial", 16, FontStyle.Italic Or FontStyle.Underline)
- ' Create a font from a family and a size in another unit.
- Dim font4 As New Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Millimeter)
-
- ' Create a font family
- Dim fontFam As New FontFamily("Courier New")
- Dim font5 As New Font(fontFam, 18, FontStyle.Italic)
-
- gr.DrawString("Arial 12 Regular", font1, Brushes.Black, 20, 20)
- gr.DrawString("Arial 14 Bold", font2, Brushes.Black, 20, 60)
- gr.DrawString("Arial 16 Italic & Underline", font3, Brushes.Black, 20, 100)
- gr.DrawString("Arial 10 millimeters", font4, Brushes.Black, 20, 140)
- gr.DrawString("Courier 18 Italic", font5, Brushes.Black, New PointF(20, 200))
-
- ' Redraw the same font output with a more compact line spacing.
- Dim y As Integer = 250
- gr.DrawString("Arial 12 Regular", font1, Brushes.Black, 20, y)
- y += font1.GetHeight(gr)
- gr.DrawString("Arial 14 Bold", font2, Brushes.Black, 20, y)
- y += font2.GetHeight(gr)
- gr.DrawString("Arial 16 Italic & Underline", font3, Brushes.Black, 20, y)
- y += font3.GetHeight(gr)
- gr.DrawString("Arial 10 millimeters", font4, Brushes.Black, 20, y)
- y += font4.GetHeight(gr)
- gr.DrawString("Courier 18 Italic", font5, Brushes.Black, New PointF(20, y))
- y += font5.GetHeight(gr)
-
- font1.Dispose()
- font2.Dispose()
- font3.Dispose()
- font4.Dispose()
- font5.Dispose()
- gr.Dispose()
- End Sub
-
- Private Sub mnuTextureBrush_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuTextureBrush.Click
- ' let the menu disappear.
- Threading.Thread.Sleep(500)
-
- ' Draw all font names on form
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
- ' Create a textured brush.
- Dim br As New TextureBrush(Image.FromFile("greenstone.bmp"))
- ' create a large font.
- Dim fnt As New Font("Arial", 50, FontStyle.Bold, GraphicsUnit.Millimeter)
- ' Paint a string with textured pattern.
- gr.DrawString("Textured", fnt, br, 20, 20)
- gr.DrawString("Text", fnt, br, 20, 200)
-
- fnt.Dispose()
- br.Dispose()
- gr.Dispose()
- End Sub
-
- Private Sub mnuAlignedText_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuAlignedText.Click
- ' let the menu disappear.
- Threading.Thread.Sleep(500)
-
- ' Draw all font names on form
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
-
- Dim msg As String = "This is a long string whose purpose is to show how" _
- & " you can format a message inside a rectangle."
-
- Dim fnt As New Font("Arial", 12)
- Dim rectF As RectangleF
-
- ' Draw the text inside the rectangle.
- rectF = New RectangleF(20, 20, 140, 160)
- gr.DrawString(msg, fnt, Brushes.Black, rectF)
- ' Also display the bounding rectangle.
- gr.DrawRectangle(Pens.Red, 20, 20, 140, 160)
-
- ' Draw the text again, but align it to the right.
- Dim strFormat As New StringFormat()
- strFormat.Alignment = StringAlignment.Far
- ' Draw the text inside the rectangle, with the format string.
- rectF = New RectangleF(220, 20, 140, 160)
- gr.DrawString(msg, fnt, Brushes.Black, rectF, strFormat)
- ' Also display the bounding rectangle.
- gr.DrawRectangle(Pens.Red, 220, 20, 140, 160)
-
- ' Draw the text again, but center it horizontally AND vertically.
- strFormat.Alignment = StringAlignment.Center
- strFormat.LineAlignment = StringAlignment.Center
- ' Draw the text inside the rectangle, with the format string.
- rectF = New RectangleF(420, 20, 140, 160)
- gr.DrawString(msg, fnt, Brushes.Black, rectF, strFormat)
- ' Also display the bounding rectangle.
- gr.DrawRectangle(Pens.Red, 420, 20, 140, 160)
-
- fnt.Dispose()
- gr.Dispose()
- End Sub
-
- Private Sub mnuVerticalText_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuVerticalText.Click
- ' let the menu disappear.
- Threading.Thread.Sleep(500)
-
- ' Draw all font names on form
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
-
- Dim msg As String = "A vertical string"
- Dim fnt As New Font("Arial", 12)
- Dim strFormat As New StringFormat()
- strFormat.FormatFlags = StringFormatFlags.DirectionVertical
- gr.DrawString(msg, fnt, Brushes.Black, 20, 20, strFormat)
-
- fnt.Dispose()
- gr.Dispose()
- End Sub
-
- Private Sub mnuTabStops_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuTabStops.Click
- ' let the menu disappear.
- Threading.Thread.Sleep(500)
-
- ' Draw all font names on form
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
-
- ' Prepare a message with tabs and carriage returns.
- Dim msg As String = String.Format("{0}Column 1{0}Column 2{0}Column 3{1}" _
- & "Row 1{0}Cell (1,1){0}Cell (1,2){0}Cell (1,3){1}" _
- & "Row 2{0}Cell (2,1){0}Cell (2,2){0}Cell (3,3){1}", _
- ControlChars.Tab, ControlChars.CrLf)
- Dim fnt As New Font("Arial", 12)
-
- Dim strFormat As New StringFormat()
- ' Set the tab stops.
- Dim tabStops() As Single = {80, 140, 200}
- strFormat.SetTabStops(0, tabStops)
- ' Draw the text with specified tab stops.
- gr.DrawString(msg, fnt, Brushes.Black, 20, 20, strFormat)
-
- fnt.Dispose()
- gr.Dispose()
- End Sub
-
- Private Sub mnuAntialiasing_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuAntialiasing.Click
- ' let the menu disappear.
- Threading.Thread.Sleep(500)
-
- ' Draw all font names on form
- Dim gr As Graphics = Me.CreateGraphics
- gr.Clear(Color.White)
-
- ' Draw a first ellipse in regular mode.
- gr.DrawEllipse(Pens.Black, 20, 20, 100, 60)
- ' Draw a second ellipse in anti-aliasing mode.
- gr.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
- gr.DrawEllipse(Pens.Black, 140, 20, 100, 60)
-
- Dim fnt As New Font("Arial", 14)
- gr.DrawString("Regular Text", fnt, Brushes.Black, 20, 200)
- gr.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
- gr.DrawString("Standard Anti-aliasing", fnt, Brushes.Black, 20, 260)
- gr.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
- gr.DrawString("ClearType Anti-aliasing", fnt, Brushes.Black, 20, 320)
-
- fnt.Dispose()
- gr.Dispose()
- End Sub
- End Class
-